<?php
/**
 * 投注纪录明细
 *
 *
 *
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class gamerecorddetailControl extends BaseLotteryHallControl{
	public function indexOp(){
		
		$bets_model = Model('bat');
		$user_model = Model('member');
		$model_play = Model("played");
		$model_data = Model('data_class');
						
		$param = array();		
		$uid = $_SESSION['uid'];
		$memberinfo = $user_model->getMemberInfo(array('uid'=>$uid));
		$param['username'] = $memberinfo['username'];
		
		$page = $_GET['pageIndex']?$_GET['pageIndex']:1;
		$start = 15*$page-15;
		
		$fromTime = strtotime($_GET['start']);
		$toTime = strtotime($_GET['end']);
		
		if($fromTime && $toTime){
			$fromTime = $fromTime+3600*3;
			$toTime = $toTime+3600*3;
		}else{
			$today_zero = strtotime('today');
			$time = time();
			$fromTime = $today_zero+3600*3;			//查询起始时间
			if($fromTime > $time){
				$toTime = $fromTime;				//查询结束时间
				$fromTime = $today_zero-3600*21;
			}else{
				$toTime = $fromTime+3600*24;
			}			
		}
		$param['beginDate'] = date('Y-m-d',$fromTime);
		$param['endDate'] = date("Y-m-d",$toTime);
		$condition['actionTime'] = array('between',$fromTime.','.$toTime);
		$condition['uid'] = $uid;	
		$condition['isDelete'] = 0;
		$bet_list= $bets_model->getBetList($condition,'','',$start.',15','id desc');
		if(!empty($bet_list) && is_array($bet_list)){
			foreach($bet_list as $key=>$value){
				$playinfo = $model_play->getPlayInfo(array('id'=>$value['playedId']));
				$bet_list[$key]['LotteryName'] = '重庆彩';
				$bet_list[$key]['RuleName'] = $playinfo['name'];
			}
		}		
		
		$bet_count = $bets_model->getBetCount($condition);
		if($bet_count){
			$totalpage = ceil($bet_count/15);
		}else{
			$bet_count = 0;
			$totalpage = 1;
		}
		
		$data_zj['totalPages'] = $totalpage;
		$data_zj['totalRecords'] = $bet_count;
		foreach($bet_list as $key=>$value){
			$playinfo = $model_play->getPlayInfo(array('id'=>$value['playedId']));
		
			$data_zj['rows'][$key]['RowNumber'] = $key+1;
			$data_zj['rows'][$key]['BetContent'] = $value['actionData'];						//投注号码
			$data_zj['rows'][$key]['BonusNumber'] = $value['lotteryNo'];						//开奖号码
			$data_zj['rows'][$key]['InsertDate'] = date('Y-m-d H:i:s', $value['actionTime']);	//投注时间
			$data_zj['rows'][$key]['UserName'] = $value['username'];							//用户名
			$data_zj['rows'][$key]['UserType'] = $member_info['type']==0?'会员':'代理';			//用户类型
			$data_zj['rows'][$key]['RuleName'] = $playinfo['name'];								//玩法
			$data_zj['rows'][$key]['LotteryName'] = '重庆时时彩';								//彩种
			$data_zj['rows'][$key]['Id'] = $value['id'];
			$data_zj['rows'][$key]['Uid'] = $value['uid'];										//用户UID
			$data_zj['rows'][$key]['MemberId'] = $uid;
			$data_zj['rows'][$key]['LotteryId'] = 1;											//彩种ID
			$data_zj['rows'][$key]['IssueNumber'] = $value['actionNo'];							//期号
			$data_zj['rows'][$key]['BetRuleId'] = $value['playedId'];
			$data_zj['rows'][$key]['BetUnitPrice'] = $value['mode'];
			$data_zj['rows'][$key]['UnitPaymentPrice'] = $value['bonusProp'];					//赔率
			$data_zj['rows'][$key]['ReturnPoint'] = $item['fanDian'];							//返点
			$data_zj['rows'][$key]['OrderDate'] = "/Date(".$value['actionTime'].")/";
			$data_zj['rows'][$key]['OrderStatus'] = $v['isDelete']?10:0;
			$data_zj['rows'][$key]['TotalBet'] = $value['actionNum']*$value['beiShu'];
			$data_zj['rows'][$key]['OrderGuid'] = $value['serializeId'];
			$data_zj['rows'][$key]['BonusTotalNumber'] = $value['zjCount'];
			$data_zj['rows'][$key]['Description'] = '重庆时时彩 '.$value['actionNo'].'期 '.$group[0]['groupName'];		//说明
			$data_zj['rows'][$key]['profit'] = number_format(($value['bonus']-$value['beiShu']*$value['actionNum']*$value['mode']),2);									//盈亏
			//是否开奖
			$kjdata = $model_data->getDataList(array('number'=>$value['actionNo'],'type'=>1));
			if($kjdata){
				$data_zj['rows'][$key]['hasRunLottery'] = "是";
			}else{
				$data_zj['rows'][$key]['hasRunLottery'] = "否";
			}
			$data_zj['rows'][$key]['BonusMoney'] = $value['bonus'];
			$data_zj['rows'][$key]['EncodeId'] = $value['wjorderId'];
			$data_zj['lotteryNumberDict']['1,'.$value['actionNo']] = $value['lotteryNo'];
		}
		$json = json_encode($data_zj);

		Tpl::output('json',$json);
		Tpl::output('bet_list',$bet_list);
		Tpl::output('param',$param);
		Tpl::output('page',$page);
		Tpl::output('totalpage',$totalpage);
		Tpl::output('count',$bet_count);
		Tpl::showpage('gamerecorddetail');
	}



}
